<?php namespace Home\Controller; 

use Hdphp\Controller\Controller;

//测试控制器
class IndexController extends Controller{


    //动作
    public function index(){
    	$brandModel = new \Common\Model\Brand;
		//获得品牌数据*********** 热门品牌楼层数据***********
		$brandData = $brandModel->where("is_hot=1")->orderBy('bsort','asc')->get();
		//分配数据
		View::with('brandData',$brandData);
		//***********获得最新上架商品数据***********
		$goodsModel = new \Common\Model\Goods;
		$newgoodsData = $goodsModel->orderBy('carriage_time','desc')->get();
		View::with('newgoods',$newgoodsData);
		$cateModel = new \Common\Model\Cate;
		//***********潮流上装左侧分类***********
		//取得上装的子分类的cid
		$clothingcidson = $cateModel->getSon($cateModel->get(),5);
		//把cid数组转为字符串
		$clothingcidson = implode(',', $clothingcidson);
		//获得子分类的分类名
		$clothingcateNames = $cateModel->where("cid in (".$clothingcidson.")")->get();
		//取5条属于子分类并主页图字段不为空的商品
		$clothingData = $goodsModel->where("category_cid in (".$clothingcidson.") AND indexpic !=''")->limit(5)->get();
		//取得子分类热门商品
		$hotclothing = $goodsModel->where("category_cid in (".$clothingcidson.")")->orderBy('click_rate','desc')->limit(6)->get();
		//分配数据
		View::with('hotclothing',$hotclothing);
		View::with('clothingData',$clothingData);
		View::with('clothingcatenames',$clothingcateNames);
		//***********潮流下装左侧分类***********
		//获得下装分类的子分类的cid
		$pantscidson = $cateModel->getSon($cateModel->get(),6);
		//把cid数组转为字符串 用于sql语句查询
		$pantscidson = implode(',', $pantscidson);
		//获得子分类的分类名
		$pantscateNames = $cateModel->where("cid in (".$pantscidson.")")->get();
		//取5条属于子分类并主页图字段不为空的商品
		$pantsData = $goodsModel->where("category_cid in (".$pantscidson.") AND indexpic !=''")->limit(5)->get();
		//取得子分类热门商品
		$hotpants = $goodsModel->where("category_cid in (".$pantscidson.")")->orderBy('click_rate','desc')->limit(6)->get();
		//分类数据
		View::with('hotpants',$hotpants);
		View::with('pantsData',$pantsData);
		View::with('pantscatenames',$pantscateNames);
		//***********时尚鞋履左侧分类***********
		//获得鞋履分类的子分类cid
		$shoescidson = $cateModel->getSon($cateModel->get(),14);
		//把子分类cid数组转为字符串
		$shoescidson = implode(',', $shoescidson);
		//获得子分类的分类名
		$shoescateNames = $cateModel->where("cid in (".$shoescidson.")")->get();
		//取5条属于子分类并主页图字段不为空的商品
		$shoesData = $goodsModel->where("category_cid in (".$shoescidson.") AND indexpic !=''")->limit(5)->get();
		//取得鞋履子分类的人气商品
		$hotshoes = $goodsModel->where("category_cid in (".$shoescidson.")")->orderBy('click_rate','desc')->limit(6)->get();
		//分配数据
		View::with('hotshoes',$hotshoes);
		View::with('shoesData',$shoesData);
		View::with('shoescatenames',$shoescateNames);
		//***********配饰左侧分类***********
		//获得服配分类的子分类的cid
		$pscidson = $cateModel->getSon($cateModel->get(),4);
		//把cid转为数组
		$pscidson = implode(',', $pscidson);
		//获得子分类的分类名
		$pscateNames = $cateModel->where("cid in (".$pscidson.")")->limit(12)->get();
		//取5条属于子分类并主页图字段不为空的商品
		$psData = $goodsModel->where("category_cid in (".$pscidson.") AND indexpic !=''")->limit(5)->get();
		//取得人气商品
		$hotps = $goodsModel->where("category_cid in (".$pscidson.")")->orderBy('click_rate','desc')->limit(6)->get();
		//分配数据
		View::with('hotps',$hotps);
		View::with('psData',$psData);
		View::with('pscatenames',$pscateNames);
		//***********获得人气单品商品***********
		$hotGoodsData = $goodsModel->orderBy('click_rate','desc')->limit(12)->get();
		View::with('hots',$hotGoodsData);
       	View::make();
    }
}
